package com.qumall.boot.controller;

import com.qumall.boot.common.Result;
import com.qumall.boot.controller.request.LoginRequest;
import com.qumall.boot.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/session")
public class SessionController {

    @Autowired
    SessionService sessionService;

    @PostMapping("/login")
    public Result login(@RequestBody @Valid LoginRequest request) {
        return Result.success(sessionService.login(request));
    }

    @PostMapping("/loginsms")
    public Result loginsms(@RequestBody @Valid LoginRequest request) {
        return Result.success(sessionService.loginWithSms(request));
    }

    /**
     * 获取手机验证码
     *
     * @param account 手机号
     * @return
     */
    @GetMapping("/sms")
    public Result login(@RequestParam String account) {
        sessionService.sendSms(account);
        return Result.success();
    }

}
